< previous page page_144 next page >

Page 144
Type.gifListing 5.28. Coding the InRangeValidate method.
Public Sub InRangeValidate()
    '
    ' check value within range
    '
    Dim varCheckValue As Variant
    '
    If IsNumeric(Text1.Text) = False Then
        RaiseEvent InRangeError(varCheckValue)
        Exit Sub
    Else
        varCheckValue = Text1.Text
    End If
    '
    If varCheckValue < m_LowValue Or varCheckValue > m_HighValue Then
        RaiseEvent InRangeError(varCheckValue)
    End If
    '
End Sub
Notice that the first check is to make sure that the data entry is really numeric data. Then the numeric data is compared to the min and max values set in the properties. If the comparison fails, a new error event is fired off to the host environment.
Finally, to call this routine automatically within the control, place the following code behind the Lost_Focus event for the Text1 control:
Private Sub Text1_LostFocus()
    '
    If CheckRange = True Then InRangeValidate
    '
End Sub
That's it for the range-checking features of the VText control. Save the control (VTEXT.CTL) and the project (CUSTOMVALIDATION.VBP) before you test your new features.
Testing the InRange Options of the VText Control
Select the TEST project again and add a new vText control to the form along with an OK button (see Figure 5.16).
Now set the following properties on the new VText control:
· Name
vtxInRange
· CheckRange
True
· Digits
True

 
< previous page page_144 next page >

If you like this book, buy it!